package QuanLyDatHang;

import QuanLyKhachHang.KhachHang;
import QuanLyKhachHang.ThemKhachHang;
import QuanLyThuoc.ThemThuoc;
import QuanLyThuoc.Thuoc;
import java.awt.event.ItemEvent;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.crypto.spec.IvParameterSpec;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;

public class ThemDatHang extends javax.swing.JFrame {

    DatHang dh = new DatHang();
    KhachHang kh = new KhachHang();//Lấy vào combobox
    Thuoc t = new Thuoc();
    Vector vLay = new Vector();

    public ThemDatHang() {
        setResizable(false);
        initComponents();

        try {
            vLay = kh.xemDanhSachKhachHang();
            this.layTenKhachHang(vLay);

            vLay = dh.xemDatHang();
            this.layMaDatHang(vLay);

            vLay = t.xemThuoc();
            this.layTenThuoc(vLay);

        } catch (SQLException ex) {
            Logger.getLogger(ThemDatHang.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    //Lấy tên khách hàng vào combobox
    public void layTenKhachHang(Vector vLay) {
        Vector tenKhachHang = new Vector();
        tenKhachHang.addElement("---Chọn tên Khách Hàng---");
        for (int i = 0; i < vLay.size(); i++) {
            kh = (KhachHang) vLay.get(i);
            tenKhachHang.addElement(kh.getTenKhachHang());
        }
        DefaultComboBoxModel modelTenKhachHang = new DefaultComboBoxModel(tenKhachHang);
        cbTenKhachHang.setModel(modelTenKhachHang);
    }

    //Lấy mã đặt hàng vào combobox
    public void layMaDatHang(Vector vLay) {
        Vector maDatHang = new Vector();
        maDatHang.addElement("---Chọn mã đặt hàng---");
        for (int i = 0; i < vLay.size(); i++) {
            dh = (DatHang) vLay.get(i);

            maDatHang.addElement(dh.getMaDatHang());
        }
        DefaultComboBoxModel modelMaDatHang = new DefaultComboBoxModel(maDatHang);
        cbMaDatHang.setModel(modelMaDatHang);
    }

    //Lấy tên thuốc vào combobox
    public void layTenThuoc(Vector vLay) {
        Vector tenThuoc = new Vector();
        tenThuoc.addElement("---Chọn tên thuốc---");
        for (int i = 0; i < vLay.size(); i++) {
            t = (Thuoc) vLay.get(i);

            tenThuoc.addElement(t.getTenThuoc());
        }
        DefaultComboBoxModel modelTenThuoc = new DefaultComboBoxModel(tenThuoc);
        cbTenThuoc.setModel(modelTenThuoc);
    }

    //thêm vào bảng đặt hàng
    public void themDatHang() {
        if (cbTenKhachHang.getSelectedItem().toString().trim().equals("---Chọn tên Khách Hàng---")) {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn tên khách hàng!");
            cbTenKhachHang.requestFocus();
            return;
        }
        int kt = 0;
        //Lấy mã khách hàng
        Vector maKhachHang = new Vector();
        try {
            maKhachHang = kh.xemDanhSachKhachHang();
        } catch (SQLException ex) {
            Logger.getLogger(ThemDatHang.class.getName()).log(Level.SEVERE, null, ex);
        }
        for (int i = 0; i < maKhachHang.size(); i++) {
            kh = (KhachHang) maKhachHang.get(i);
            //so sánh tên trùng thì lấy ra mã khách hàng
            if (cbTenKhachHang.getSelectedItem().toString().equals(kh.getTenKhachHang().toString())) {
                dh.setMaKhachHang((int) kh.getMaKhachHang());
            }
        }
        dh.setTenKhachHang(cbTenKhachHang.getSelectedItem().toString());
        dh.setThoiGianGiaoHang(txtThoiGianGiaoHang.getText().trim());
        dh.setDiaChiGiaoHang(txtDiaChiGiaoHang.getText().trim());
        try {
            kt = DatHang.themDatHang(dh);
            if (kt == 1) {
                JOptionPane.showMessageDialog(this, "Thêm mới Đặt hàng thành công!", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
                vLay = dh.xemDatHang();
                this.layMaDatHang(vLay);
                this.troVe();
            } else {
                JOptionPane.showMessageDialog(this, "Thêm mới không thành công.Bạn hãy xem lại", "Thông báo", JOptionPane.ERROR_MESSAGE);
            }
        } catch (SQLException ex) {
            Logger.getLogger(ThemDatHang.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    //Thêm vào bảng chi tiêt đặt hàng
    public void themCTDatHang() {
        if (cbMaDatHang.getSelectedItem().toString().trim().equals("---Chọn mã đặt hàng---")) {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn mã đặt hàng!");
            cbMaDatHang.requestFocus();
            return;
        }
        if (cbTenThuoc.getSelectedItem().toString().trim().equals("---Chọn tên thuốc---")) {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn tên thuốc!");
            cbTenThuoc.requestFocus();
            return;
        }
        if (txtSoLuong.getText().equals("")) {
            JOptionPane.showMessageDialog(this, "Bạn chưa nhập số lượng!");
            txtSoLuong.requestFocus();
            return;
        }
        int kt = 0;
        //Lấy mã khách hàng
        Vector maThuoc = new Vector();
        try {
            maThuoc = t.xemThuoc();
        } catch (SQLException ex) {
            Logger.getLogger(ThemDatHang.class.getName()).log(Level.SEVERE, null, ex);
        }
        for (int i = 0; i < maThuoc.size(); i++) {
            t = (Thuoc) maThuoc.get(i);
            //so sánh tên trùng thì lấy ra mã thuốc
            if (cbTenThuoc.getSelectedItem().toString().equals(t.getTenThuoc().toString())) {
                dh.setMaThuoc((int) t.getMaThuoc());
            }
        }
        int maDatHang = Integer.parseInt(cbMaDatHang.getSelectedItem().toString());
        dh.setMaDatHang(maDatHang);
        int soLuong = Integer.parseInt(txtSoLuong.getText());
        dh.setSoLuong(soLuong);
        try {
            kt = DatHang.themCTDatHang(dh);
            if (kt == 1) {
                JOptionPane.showMessageDialog(this, "Thêm mới chi tiết Đặt hàng thành công!", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
                this.troVe();

            } else {
                JOptionPane.showMessageDialog(this, "Thêm mới không thành công.Bạn hãy xem lại", "Thông báo", JOptionPane.ERROR_MESSAGE);
            }
        } catch (SQLException ex) {
            Logger.getLogger(ThemDatHang.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    //Trở về 

    public void troVe() {
        cbTenKhachHang.setSelectedIndex(0);
        txtThoiGianGiaoHang.setText("");
        txtDiaChiGiaoHang.setText("");
        cbMaDatHang.setSelectedIndex(0);
        cbTenThuoc.setSelectedIndex(0);
        txtSoLuong.setText("");
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        cbTenKhachHang = new javax.swing.JComboBox();
        txtThoiGianGiaoHang = new javax.swing.JTextField();
        txtDiaChiGiaoHang = new javax.swing.JTextField();
        btThemDatHang = new javax.swing.JButton();
        btThemKhachHangMoi = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        cbMaDatHang = new javax.swing.JComboBox();
        cbTenThuoc = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        txtSoLuong = new javax.swing.JTextField();
        btThemDatHang_Thuoc = new javax.swing.JButton();
        btThemThuoc = new javax.swing.JButton();
        btDong = new javax.swing.JButton();
        btTroLai = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Bảng đặt hàng"));

        jLabel1.setText("Tên Khách hàng");

        jLabel2.setText("Thời gian giao hàng");

        jLabel3.setText("Địa chỉ giao hàng");

        cbTenKhachHang.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        txtThoiGianGiaoHang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtThoiGianGiaoHangActionPerformed(evt);
            }
        });

        btThemDatHang.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/add 1.png"))); // NOI18N
        btThemDatHang.setText("Thêm đặt hàng");
        btThemDatHang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btThemDatHangActionPerformed(evt);
            }
        });

        btThemKhachHangMoi.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/add 1.png"))); // NOI18N
        btThemKhachHangMoi.setText(" Khách Hàng Mới");
        btThemKhachHangMoi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btThemKhachHangMoiActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(btThemDatHang, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btThemKhachHangMoi, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(24, 24, 24))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(7, 7, 7)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(cbTenKhachHang, 0, 183, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(txtThoiGianGiaoHang, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)
                                .addComponent(txtDiaChiGiaoHang)))
                        .addContainerGap(54, Short.MAX_VALUE))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1))
                    .addComponent(cbTenKhachHang, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtThoiGianGiaoHang, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(44, 44, 44)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtDiaChiGiaoHang, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 47, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btThemDatHang)
                    .addComponent(btThemKhachHangMoi))
                .addGap(34, 34, 34))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Bảng Đạt hàng_Thuốc"));

        jLabel4.setText("Mã Đặt Hàng");

        jLabel5.setText("Tên thuốc");

        cbMaDatHang.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbMaDatHang.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbMaDatHangItemStateChanged(evt);
            }
        });

        cbTenThuoc.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel6.setText("Số lượng");

        txtSoLuong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtSoLuongActionPerformed(evt);
            }
        });

        btThemDatHang_Thuoc.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/add 1.png"))); // NOI18N
        btThemDatHang_Thuoc.setText("Thêm chi tiết đặt hàng");
        btThemDatHang_Thuoc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btThemDatHang_ThuocActionPerformed(evt);
            }
        });

        btThemThuoc.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/add 1.png"))); // NOI18N
        btThemThuoc.setText("Thêm thuốc mới");
        btThemThuoc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btThemThuocActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE))
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(27, 27, 27)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtSoLuong)
                            .addComponent(cbTenThuoc, 0, 198, Short.MAX_VALUE)
                            .addComponent(cbMaDatHang, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(0, 63, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btThemDatHang_Thuoc)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                        .addComponent(btThemThuoc, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(cbMaDatHang, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(cbTenThuoc, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(41, 41, 41)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtSoLuong, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btThemDatHang_Thuoc)
                    .addComponent(btThemThuoc))
                .addGap(33, 33, 33))
        );

        btDong.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/exit.png"))); // NOI18N
        btDong.setText("Đóng ");
        btDong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btDongActionPerformed(evt);
            }
        });

        btTroLai.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/Go-back.png"))); // NOI18N
        btTroLai.setText("Trở lại");
        btTroLai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btTroLaiActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btDong, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btTroLai, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btTroLai)
                    .addComponent(btDong))
                .addGap(0, 55, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtThoiGianGiaoHangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtThoiGianGiaoHangActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtThoiGianGiaoHangActionPerformed

    private void txtSoLuongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtSoLuongActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtSoLuongActionPerformed

    private void btThemDatHangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btThemDatHangActionPerformed
        // TODO add your handling code here:
        this.themDatHang();
    }//GEN-LAST:event_btThemDatHangActionPerformed

    private void btThemDatHang_ThuocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btThemDatHang_ThuocActionPerformed
        // TODO add your handling code here:
        this.themCTDatHang();
    }//GEN-LAST:event_btThemDatHang_ThuocActionPerformed

    private void btDongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btDongActionPerformed
        // TODO add your handling code here:
        int thongBao = JOptionPane.showConfirmDialog(null, "Bạn có muốn đóng thêm Đặt hàng?", "Thông báo", JOptionPane.YES_NO_OPTION);
        if (thongBao == JOptionPane.YES_OPTION) {
            this.dispose();
        }
    }//GEN-LAST:event_btDongActionPerformed

    private void btTroLaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btTroLaiActionPerformed
        // TODO add your handling code here:
        this.troVe();
    }//GEN-LAST:event_btTroLaiActionPerformed

    private void cbMaDatHangItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbMaDatHangItemStateChanged
        // TODO add your handling code here:
        if (evt.getStateChange() == ItemEvent.SELECTED) {
            Vector vDatHang = new Vector();
            try {
                vDatHang = DatHang.xemDatHang();
                for (int i = 0; i < vDatHang.size(); i++) {
                    dh = (DatHang) vDatHang.get(i);

                    if (cbMaDatHang.getSelectedItem() == dh.getMaDatHang()) {
                        cbTenKhachHang.setSelectedItem(dh.getTenKhachHang());
                        txtDiaChiGiaoHang.setText(dh.getDiaChiGiaoHang());
                        txtThoiGianGiaoHang.setText(dh.getThoiGianGiaoHang());
                    }

                }
            } catch (SQLException ex) {
                Logger.getLogger(ThemDatHang.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }//GEN-LAST:event_cbMaDatHangItemStateChanged

    private void btThemKhachHangMoiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btThemKhachHangMoiActionPerformed
        // TODO add your handling code here:
        new ThemKhachHang().setVisible(true);
    }//GEN-LAST:event_btThemKhachHangMoiActionPerformed

    private void btThemThuocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btThemThuocActionPerformed
        // TODO add your handling code here:
        new ThemThuoc().setVisible(true);
    }//GEN-LAST:event_btThemThuocActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ThemDatHang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ThemDatHang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ThemDatHang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ThemDatHang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ThemDatHang().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btDong;
    private javax.swing.JButton btThemDatHang;
    private javax.swing.JButton btThemDatHang_Thuoc;
    private javax.swing.JButton btThemKhachHangMoi;
    private javax.swing.JButton btThemThuoc;
    private javax.swing.JButton btTroLai;
    private javax.swing.JComboBox cbMaDatHang;
    private javax.swing.JComboBox cbTenKhachHang;
    private javax.swing.JComboBox cbTenThuoc;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField txtDiaChiGiaoHang;
    private javax.swing.JTextField txtSoLuong;
    private javax.swing.JTextField txtThoiGianGiaoHang;
    // End of variables declaration//GEN-END:variables
}
